package com.gosophia.oa.test.functional;

import org.junit.After;
import org.junit.Before;

import com.gosophia.oa.test.CustomSeleneseTestCase;



public class FTOrganizationManagement extends CustomSeleneseTestCase {

	@Before
	public void setUp() throws Exception {
		super.setUp("http://localhost:8080/");
	}

	@After
	public void tearDown() throws Exception {
		if (selenium != null)
			selenium.close();
		super.tearDown();
	}

	public void testTreePage() {
		// 登录
		selenium.open("/OA/");
		selenium.type("j_username", "admin");
		selenium.type("j_password", "admin");
		selenium.click("loginBtn");
		selenium.waitForPageToLoad("10000");

		// 进入页面
		selenium.click("link=机构管理");
		selenium.waitForPageToLoad("10000");
		assertPageTitle("北京市电子行政监察平台-机构管理", onPage("机构管理页面"));
		
		// 验证树形组件元素
		String[] listPageElementTexts = {
				"机构管理",
				"全部展开"
				};
		verifyPresenceOfTexts(listPageElementTexts, onPage("机构管理页面"));

		// 展开/折叠
		selenium.click("link=全部展开");
		waitForDisappearanceOfText("全部展开", 10000);
		verifyPresenceOfText("全部折叠", onPage("机构管理页面"));

		// 新建同级
		selenium.click("add");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='新建同级机构']", 10000);		
		String[] addPageElementTexts = {
				"机构名称",
				"机构简称",
				"机构代码",
				"机构电话",
				"机构传真",
				"电子邮件",
				"机构地址",
				"描述"
				};
		verifyPresenceOfTexts(addPageElementTexts, onPage("新建同级机构子页面"));

		// 新建下级
		selenium.click("add-child");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='新建下级机构']", 10000);		
		String[] addChildPageElements = {
				"机构名称",
				"机构简称",
				"机构代码",
				"机构电话",
				"机构传真",
				"电子邮件",
				"机构地址",
				"描述"
				};
		verifyPresenceOfTexts(addChildPageElements, onPage("新建下级机构子页面"));
		
		// 详细
		selenium.click("//span[@name='工商局']");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='机构详细信息']", 10000);		
		String[] detailsPageElementTexts = {
				"机构名称",
				"机构简称",
				"机构代码",
				"机构电话",
				"机构传真",
				"电子邮件",
				"机构地址",
				"邮编",
				"描述"
				};
		verifyPresenceOfTexts(detailsPageElementTexts, onPage("机构详细子页面"));
		
		// 编辑
		selenium.click("edit");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='编辑机构']", 10000);		
		String[] editPageElementTexts = {
				"机构名称",
				"机构简称",
				"机构代码",
				"机构电话",
				"机构传真",
				"电子邮件",
				"机构地址",
				"描述"
				};
		verifyPresenceOfTexts(editPageElementTexts, onPage("编辑机构子页面"));
	}
}
